﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;

namespace Urb.Weather.Ticker.UI.Converters
{
    [ValueConversion(typeof(DateTimeOffset?), typeof(string))]
    public class DateTimeOffsetToLocalDateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || !(value is DateTimeOffset?))
                return string.Empty;

            var dateTimeOffset = (DateTimeOffset?)value;

            if (!dateTimeOffset.HasValue)
                return string.Empty;

            return dateTimeOffset.Value.LocalDateTime.ToString("g", CultureInfo.CurrentUICulture);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
